package six

import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.mutable.ListBuffer

object MapPartitionsTestScala {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("TestTransformation").setMaster("local")
    val sc = new SparkContext(conf)

    val list = List(1,2,3,4,5,6)
    val listRDD = sc.parallelize(list,2)

    listRDD.mapPartitions(iterator => {
      val list: ListBuffer[String] = ListBuffer()
      while (iterator.hasNext) {
        list.append("Hello " + iterator.next())
      }
      list.toIterator
    }).foreach(name => println(name))
  }
}
